local skill = fk.CreateSkill {
  name = "ty1v2__drowning_skill",
}

local function shallowCopy(t)
    if type(t) ~= "table" then return t end
    local copy = {}
    for k, v in pairs(t) do
        copy[k] = v
    end
    return copy
end

skill:addEffect("cardskill", {
  prompt = "#ty1v2__drowning_skill",
  min_target_num = 1,
  max_target_num = 2,
  mod_target_filter = Util.TrueFunc,
  target_filter = Util.CardTargetFilter,
  on_use = function(self, room, use)
    use.extra_data = use.extra_data or {}
    use.extra_data.ty1v2_drowning_targets = shallowCopy(use.tos)
  end,
  on_action = function(self, room, use)
    if type((use.extra_data or {}).ty1v2_drowning_targets) == "table" then
        use.tos = shallowCopy(use.extra_data.ty1v2_drowning_targets)
    end
  end,
  on_effect = function(self, room, effect)
    local from = effect.from
    local to = effect.to
    room:damage{
      from = from,
      to = to,
      card = effect.card,
      damage = 1,
      damageType = fk.ThunderDamage,
      skillName = skill.name
    }
    if not to.dead then
      if effect.use.tos[1] == effect.to then
        room:askToDiscard(to, {
          min_num = 1,
          max_num = 1,
          include_equip = true,
          skill_name = skill.name,
          cancelable = false,
        })
      else
        to:drawCards(1, skill.name)
      end
    end
  end,
})

return skill
